<template>
  <el-form ref="formRef" :model="form" label-width="280px" status-icon>
    <el-form-item label="通用模板code" prop="com_sms_code">
      <el-input v-model="form.com_sms_code" clearable style="width:280px"/>
    </el-form-item>
    <el-form-item label="用户登录模板code" prop="login_sms_code">
      <el-input v-model="form.login_sms_code" clearable style="width:280px"/>
    </el-form-item>
    <el-form-item label="用户注册模板code" prop="reg_sms_code">
      <el-input v-model="form.reg_sms_code" clearable style="width:280px"/>
    </el-form-item>
    <el-form-item label="密码找回模板code" prop="forget_sms_code">
      <el-input v-model="form.forget_sms_code" clearable style="width:280px"/>
    </el-form-item>
    <el-form-item label="手机号码绑定模板code" prop="bind_sms_code">
      <el-input v-model="form.bind_sms_code" clearable style="width:280px"/>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" plain v-debounce="handleSubmit">保存</el-button>
    </el-form-item>
  </el-form>
</template>

<script setup lang="ts">
import { ref, onMounted } from "vue";
import { getConfig } from "@/api/system/config";

// 定义参数的类型
interface IConfigProps {
  configKey?: string;
  name?: string;
}

// 子组件接收父组件的值
// withDefaults：设置默认值  defineProps：接收父组件的参数
const props = withDefaults(defineProps<IConfigProps>(), {
  name: "",
  configKey: ""
});

onMounted(() => {
  getConfig({ key: props.configKey }).then(res => {
    if (Object.keys(res.data).length > 0) {
      form.value = res.data;
    }
  });
});

// 当前组件获取父组件传递的事件方法
const emits = defineEmits(["handleSubmit"]);
// 弹框的确定事件
const handleSubmit = () => {
  emits("handleSubmit", form.value);
};

let form = ref<any>({
  com_sms_code: "",
  login_sms_code: "",
  reg_sms_code: "",
  forget_sms_code: "",
  bind_sms_code: ""
});
</script>

<style lang="scss" scoped></style>
